package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.entity.Borrower;
import com.atguigu.srb.core.entity.vo.ApprovalForm;
import com.atguigu.srb.core.entity.vo.BorrowerDetailVo;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-06-30
 */
@RestController
@RequestMapping("/admin/core/borrower")
@Api(tags = "用户借款审批模块")
public class AdminBorrowerController {
    @Resource
    BorrowerService borrowerService;

    @ApiOperation("带条件的分页查询模块")
    @GetMapping("list/{pageNum}/{pageSize}")
    public R listPage(@PathVariable("pageNum")Integer pageNum,
                      @PathVariable("pageSize")Integer pageSize,
                      //这个地方没有使用@RequestParam表示keywork这个参数不是必须的
                      String keyword){
        Page<Borrower> borrowerPage = borrowerService.listPage(pageNum,pageSize,keyword);
        return R.ok().data("item",borrowerPage);
    }
    @ApiOperation("根据borrowerId查询借款人的详细信息")
    //这个地方需要用户的token吗(感觉可以不用) admin里面的controller就不需要auth了
    @GetMapping("/detail/{borrowerId}")
    public R getBorrowerInfo(@PathVariable("borrowerId")Long borrowerId){
        BorrowerDetailVo borrowerDetailVo = borrowerService.getDetail(borrowerId);
        return R.ok().data("item",borrowerDetailVo);
    }
    @ApiOperation(("借款人信息审批"))
    @PutMapping("/approval")
    public R approvalBorrower(@RequestBody ApprovalForm approvalForm){
        borrowerService.approval(approvalForm);
        return R.ok();
    }

}

